﻿using System;
using System.Collections.Generic;
using System.Text;
using KaiXin001er.Objects;
using KaiXin001er.UTIL;
using System.Windows.Forms;

namespace KaiXin001er.Logic
{
    public class SlavePlayer : BasePlayer
    {
        public SlavePlayer(Account acct):base(acct)
        {
           
        }
        public override bool SignOn()
        {
            return true;
        }

        public override bool SignOff()
        {
            return true;
        }

        public override bool PlayPlay()
        {
            string indexPage=dac.GetRequest(URLS.朋友买卖首页, "");
            LastVerify = StringHelper.getMiddleString("var g_verify = \"", "\";", indexPage);
            朋友买卖信息 indexInfo = 页面分析者.读取朋友买卖信息(indexPage);
            RaiseMsg("[朋友买卖模块]　"+indexInfo.我是谁的奴隶);
            RaiseMsg("         身价:　" + indexInfo.身价);
            RaiseMsg("         现金:　" + indexInfo.现金);
            RaiseMsg("         总资产:　" + indexInfo.总资产);
            RaiseMsg("         奴隶数: " + indexInfo.奴隶数);
            foreach (奴隶信息 slaveInfo in indexInfo.奴隶)
            {
                RaiseMsg("\r\n[朋友买卖模块]　奴隶" + slaveInfo.名字);
                RaiseMsg("         身价:　" + slaveInfo.身价);
                RaiseMsg("         现金:　" + slaveInfo.现金);
                RaiseMsg("         总资产:　" + slaveInfo.总资产);
                RaiseMsg("         奴隶数: " + slaveInfo.奴隶数);
            }
            安抚奴隶(indexInfo);
            return true;
        }
        private void 购买奴隶()
        {
           //取我买得起的奴隶

           //显示出来让用户选择　支持多选　多选的时候随时计算金额比对一下是不是超了能力了？

           //执行多选的购买
        }
        private void 安抚奴隶(朋友买卖信息 indexInfo)
        {
            foreach (奴隶信息 slaveInfo in indexInfo.奴隶)
            {
                请求参数 comfotr = new 请求参数();
                comfotr.add("rand", RandomGen.随机小数());
                comfotr.add("slaveuid",slaveInfo.ID);
                comfotr.add("verify", this.LastVerify);
                string comfortlist = dac.GetRequest(URLS.安抚奴隶列表, comfotr.ToString());
                
                安抚列表 list = 页面分析者.读取安抚列表(comfortlist);
                if (list.安抚信息列表 == null) continue;
                if (list.安抚信息列表.Count == 0) continue;
                frmSlaveComfortList frm = new frmSlaveComfortList(list);
                frm.Text = slaveInfo.名字;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //进行安抚
                    请求参数 cr = new 请求参数();
                    cr.add("comforttype", frm.selectedValue.Value);
                    cr.add("slaveuid", slaveInfo.ID);
                    cr.add("verify", LastVerify);
                    string comforResultPage = dac.PostRequest(URLS.安抚奴隶, cr.ToString());
                    comforResultPage = "";
                    RaiseMsg("[朋友买卖模块]　安抚" + slaveInfo.名字 + ":" + frm.selectedValue.Desc);
                }
                else
                {
                    RaiseMsg("[朋友买卖模块] 取消对"+slaveInfo.名字+"的安抚");
                }
            }

        }
    }
}
